﻿using NServiceBus.Management.Messages.EndpointControl;
using NServiceBus.Management.Messages.Status;
using NServiceBus.Management.Messages.Tracking;

namespace NServiceBus.Management.ManagementService.MessageHandlers
{
    public class StatusMessageHandler : IMessageHandler<OfflineMessage>,
                                                   IMessageHandler<OnlineMessage>,
                                                IMessageHandler<PingResponse>,
                                                   IMessageHandler<TrackingDataMessage>
    {
        public IBus Bus { get; set; }
        public IManagementService Manager { get; set; }

        #region MessageHandler Members
        public void Handle(OfflineMessage message)
        {
            //todo notify manager that endpoint is offline
            // Bus.Publish(new OfflineEvent { EndpointMessage = message.EndpointMessage });
        }

        public void Handle(OnlineMessage message)
        {
            Manager.RegisterNewEndpoint(message.EndpointId, message.EndpointAdress);
        }

        public void Handle(TrackingDataMessage message)
        {
            //TODO: add code here
        }


        public void Handle(PingResponse message)
        {
            Manager.UpdateStatusTimeForEndoint(message.EndpointId);
        }

        #endregion
    }
}
